﻿@using viBook.Models
@model IEnumerable<Book>
<script type="text/javascript">
    function Book(id, title, description) {
        return {
            id: ko.observable(id),
            title: ko.observable(title),
            description: ko.observable(description)
        };
    }

    var initialBookCollection = [
        @foreach (Book item in Model)
        {
            <text>
                new Book(@item.Id, '@item.Title', '@item.Description'),
            </text>
        }
    ];
    var viewmodel = {
        bookCollection: ko.observableArray(initialBookCollection),
        bookTemplate: ko.observable("ListBookTemplate"),
        changeTemplate: function() {
            if (this.bookTemplate() == 'ListBookTemplate')
                this.bookTemplate("GridBookTemplate_");
        }
    };

    ko.applyBindings(viewmodel);
</script>